/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sellcar;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author Fabio Valenzuela
 */
public class Cadastro_VeiculoDAO {
    private Connection connection;
    
    public Cadastro_VeiculoDAO(){
        this.connection = new ConnectionFactory().getConnection();
    }
    public void adiciona (Veiculo veiculo){
        String sql = "insert into tb_cadastro_veiculos" + "(DESC_ORIGEM,DESC_ESTADO,ID_MARCA,ID_MODELO,DESC_MODELO_ANO,PLACA,KILOMETRAGEM,COR,AIRBAG,ALARME,AR_CONDICIONADO,CD_PLAYER,DVD_PLAYER,DIR_HIDRAULICA,FREIOS_ABS,TRAVAS_ELETR,VIDROS_ELETR,VALOR_COMPRA,TETO_SOLAR,SENSOR_ESTAC,BANCO_COURO,LIMPADOR_TRAS,DESEMB_TRASEIRO,COMP_BORDO,id_combustivel,id_cambio,id_porta)" + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        
        try{
            PreparedStatement stmt = connection.prepareStatement(sql);
            
            stmt.setString(1, veiculo.getOrigem());
            stmt.setString(2, veiculo.getEstado());
            stmt.setInt(3, veiculo.getMarca());
            stmt.setInt(4, veiculo.getModelo());
            stmt.setString(5, veiculo.getFab());
            stmt.setString(6, veiculo.getPlaca());
            stmt.setString(7, veiculo.getKm());
            stmt.setString(8, veiculo.getCor());
            stmt.setBoolean(9, veiculo.getAirBag());
            stmt.setBoolean(10, veiculo.getAlarme());
            stmt.setBoolean(11, veiculo.getArCond());
            stmt.setBoolean(12, veiculo.getCd());
            stmt.setBoolean(13, veiculo.getDvd());
            stmt.setBoolean(14, veiculo.getDirHi());     
            stmt.setBoolean(15, veiculo.getAbs());
            stmt.setBoolean(16, veiculo.getTravas());
            stmt.setBoolean(17, veiculo.getVidros());
            stmt.setBigDecimal(18, veiculo.getValorComp());
            stmt.setBoolean(19, veiculo.getTeto());
            stmt.setBoolean(20, veiculo.getSensor());
            stmt.setBoolean(21, veiculo.getBanco());
            stmt.setBoolean(22, veiculo.getLimpador());
            stmt.setBoolean(23, veiculo.getDesen());
            stmt.setBoolean(24, veiculo.getCompu());
            stmt.setInt(25, veiculo.getCambio());
            stmt.setInt(26, veiculo.getCombust());
            stmt.setInt(27, veiculo.getPortas());
            
            stmt.execute();
            stmt.close();
            connection.close();
                
        }catch(SQLException e ){
            throw new RuntimeException(e);
        }
    }
}
